package com.yunfeng.supercall.manager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.sina.weibo.sdk.api.TextObject;
import com.sina.weibo.sdk.api.WeiboMessage;
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;
import com.sina.weibo.sdk.api.share.SendMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.WeiboShareSDK;
import com.tencent.connect.share.QQShare;
import com.tencent.tauth.Tencent;
import com.yunfeng.supercall.activity.BaseActivity;
import com.yunfeng.supercall.activity.MainActivity;
import com.yunfeng.supercall.bean.Constants;
import com.yunfeng.supercall.bean.ShareConfigBean;

public class ShareManager {

	public static void shareToQQ(final Context context) {
		final Tencent mTencent = Tencent.createInstance(Constants.QQ_KEY,
				context);
		final Bundle params = new Bundle();
		// 分享类型
		// params.putInt(QQShare.share_to_qq,
		// QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
		params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
				QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
		params.putString(QQShare.SHARE_TO_QQ_TITLE,
				ShareConfigBean.sConfig.getTitle());// 必填
		params.putString(QQShare.SHARE_TO_QQ_SUMMARY,
				ShareConfigBean.sConfig.getContent());// 选填
		try {

			params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, BaseActivity
					.getLoginManager(context).getRegUrl());// 必填
		} catch(NullPointerException e) {

		}
		params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "超号");
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				mTencent.shareToQQ((Activity) context, params,
						MainActivity.qZoneShareListener);

			}
		}).start();
	}

	public static void shareToWeiBo(Context context) {
		IWeiboShareAPI mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(context,
				Constants.SINA_WEIBO_KEY);
		mWeiboShareAPI.registerApp();
		TextObject object = new TextObject();
		object.text = ShareConfigBean.sConfig.getContent()
				+ BaseActivity.getLoginManager(context).getRegUrl();
		object.title = ShareConfigBean.sConfig.getTitle();
		object.actionUrl = BaseActivity.getLoginManager(context).getRegUrl();
		WeiboMessage weiboMessage = new WeiboMessage();
		weiboMessage.mediaObject = object;
		SendMessageToWeiboRequest request = new SendMessageToWeiboRequest();
		request.transaction = String.valueOf(System.currentTimeMillis());
		request.message = weiboMessage;
		mWeiboShareAPI.sendRequest(request);
	}

	public static void shareToSms(Context context) {
		try {
			Intent it = new Intent(Intent.ACTION_VIEW);
			it.putExtra("sms_body", ShareConfigBean.sConfig.getContent()
					+ BaseActivity.getLoginManager(context).getRegUrl());
			it.setType("vnd.android-dir/mms-sms");
			context.startActivity(it);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Toast.makeText(context, "您的设备不支持发送短信", Toast.LENGTH_SHORT).show();
		}
	}
}
